package com.consumer.service.controller;


import com.conmmon.service.DubboDemoService;
import com.conmmon.service.dto.UserReq;
import com.conmmon.service.dto.UserResp;

import javax.annotation.Resource;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ConsumerDemo
 *
 * @author H
 * @version 1.0
 * @date 2023-08-21 14:49
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    //直连模式
    //@DubboReference(url = "dubbo://127.0.0.1:15511", version = "1.0.0")
    @DubboReference(version = "1.0.0")
    private DubboDemoService dubboDemoService;
    @Resource(name = "rpcProxyFactoryBean")
    private DubboDemoService proxyUserService;

    @GetMapping("/sayHello")
    public ResponseEntity<String> sayHello(@RequestParam("name") String name) {

        return ResponseEntity.ok(dubboDemoService.helloDubbo(name));
    }

    @GetMapping("/user")
    public ResponseEntity<UserResp> userInfo(@RequestParam String id) {
        return ResponseEntity.ok(dubboDemoService.queryUserInfo(UserReq.builder().id(id).build()));
    }

    @GetMapping("/rpc")
    public ResponseEntity<UserResp> userInfoRpc(@RequestParam String id) {
        return ResponseEntity.ok(proxyUserService.queryUserInfo(UserReq.builder().id(id).build()));
    }


}
